<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%api_role_route}}".
 *
 * @property integer $id
 * @property integer $api_role_id
 * @property integer $api_route_id
 *
 * @property ApiRole $apiRole
 * @property ApiRoute $apiRoute
 */
class ApiRoleRoute extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%api_role_route}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['api_role_id', 'api_route_id'], 'required'],
            [['api_role_id', 'api_route_id'], 'integer'],
            [['api_role_id', 'api_route_id'], 'unique', 'targetAttribute' => ['api_role_id', 'api_route_id'], 'message' => 'The combination of Api Role ID and Api Route ID has already been taken.'],
            [['api_role_id'], 'exist', 'skipOnError' => true, 'targetClass' => ApiRole::className(), 'targetAttribute' => ['api_role_id' => 'id']],
            [['api_route_id'], 'exist', 'skipOnError' => true, 'targetClass' => ApiRoute::className(), 'targetAttribute' => ['api_route_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'api_role_id' => 'Api Role ID',
            'api_route_id' => 'Api Route ID',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getApiRole()
    {
        return $this->hasOne(ApiRole::className(), ['id' => 'api_role_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getApiRoute()
    {
        return $this->hasOne(ApiRoute::className(), ['id' => 'api_route_id']);
    }
}
